package com.hcinfos.gsoo.view;

import com.hcinfos.gsoo.R;

import android.content.Context;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.ImageView;

public class CleanerView extends ImageView {
	private float mTouchStartX;
	private float mTouchStartY;
	private float x;
	private float y;

	private WindowManager mWindowManager;
	private WindowManager.LayoutParams mWml;

	public void setWindowManager(WindowManager wm,
			WindowManager.LayoutParams wml) {
		mWindowManager = wm;
		mWml = wml;
	}

	public CleanerView(Context context) {
		super(context);
	}

	private OnClickListener mClickListener;

	public void setOnClickListener(OnClickListener listener) {
		mClickListener = listener;
	}

	private int movePoints = 0;

	@Override
	public boolean onTouchEvent(MotionEvent event) {
//		x = event.getRawX();
//		y = event.getRawY();
//		switch (event.getAction()) {
//		case MotionEvent.ACTION_DOWN:
//			movePoints = 0;
//			mTouchStartX = event.getX();
//			mTouchStartY = event.getY();
//			break;
//		case MotionEvent.ACTION_MOVE:
//			movePoints++;
//			setImageResource(R.drawable.im_logo);
//			updateViewPosition();
//			break;
//
//		case MotionEvent.ACTION_UP:
//			if (x > mWindowManager.getDefaultDisplay().getWidth() / 2) {
//				setImageResource(R.drawable.im_logo);
//				resetViewPosition((int) mWindowManager.getDefaultDisplay()
//						.getWidth(), (int) y);
//			} else {
//				setImageResource(R.drawable.im_logo);
//				resetViewPosition(0, (int) y);
//			}
//
//			mTouchStartX = mTouchStartY = 0;
//			if (movePoints < 10) {
//				mClickListener.onClick(this);
//			}
//			break;
//		}
		return true;
	}

	private void updateViewPosition() {
		mWml.x = (int) (x - mTouchStartX);
		mWml.y = (int) (y - mTouchStartY);
		mWindowManager.updateViewLayout(this, mWml);
	}

	private void resetViewPosition(int x, int y) {
//		mWml.x = x;
//		mWml.y = y
//				- getResources().getDrawable(R.drawable.im_logo)
//						.getMinimumHeight();
//		mWindowManager.updateViewLayout(this, mWml);
	}

}
